// pages/Main/mainIndex/mainIndex.js
var businessLogic = require('../../../utils/NetWork/Model/MainbusinessLogic.js')
var common = require('../../../utils/common.js')
let asign = 0;
let bbb = [];
Page({

  /**
   * 页面的初始数据
   */
  data: {
    content: [],
    class: "学生列表",
    job: "作业列表",
    curNavId: "xx",
    orgid: "",
    userid: "",
    rid: "",
    e: 0,

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    let c = common.Getorgid();

    this.setData({
      orgid: c.orgid,
      userid: c.userid,
      index: "",
    });
    /* this.list(); */
    //判断遍历
    //console.log("ridyuan", c.rid);
    var res = c.rid.split(',');

    var arrs = [];
    for (var i = 1; i < res.length - 1; i++) {
      arrs[i-1] = res[i].split('|');
    }
    // console.log("rid", res);
    var arr = [];
    var bbb = [];
    for (var i = 0; i < arrs.length; i++) {
      arr[i] = arrs[i][3];
    }
    console.log(arr);
    this.setData({
      rid: arr
    })
    this.list();
  },

  list: function (alength, data, res) {
    common.showLoading("加载中", "loading");
    var aaa = [];
    if (asign == alength) {
      asign = 0;
      //return false;
      //console.log(bbb)
    } else {
      let params = { "userid": this.data.userid, "orgid": this.data.orgid, "id": this.data.rid[asign] }
      businessLogic.GradeClass(params, (res) => {
        bbb.push(res);
        //console.log("12",res) 
        this.setData({
          content: bbb
        });
        asign += 1;
        this.list(this.data.rid.length, data, res);
        common.hideLoading();
      })

    }
  },
  onChangeShowState: function (e) {

    let id = e.currentTarget.dataset.id,
      index = parseInt(e.currentTarget.dataset.index)
    var that = this;

    if (this.data.curNavId == index) {
      that.setData({
        curNavId: "xx",
      })
    } else {
      that.setData({
        curNavId: index,
      })
    }
   
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // this.setData({
    //   content: []
    // })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    bbb = [];
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  studentItem: function (event) {
    wx.navigateTo({
      url: "../studentItem/studentItem?id=" + event.currentTarget.dataset.id
    });
    //console.log(event.currentTarget.dataset.id)
  },
  workList: function (event) {
    wx.navigateTo({
      url: "../workList/workList?id=" + event.currentTarget.dataset.id
    });

  },
})